<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<%
			String path = request.getContextPath();
			//String fbh = request.getParameter("fbh");
		%>
		<title>模板设置</title>
		<link rel="stylesheet" type="text/css"
			href="<%=path%>/css/btn_class.css" />
		<link rel="stylesheet" type="text/css"
			href="<%=path%>/extjs/resources/css/ext-all.css" />
		<link rel="stylesheet" type="text/css"
			href="<%=path%>/extjs/style.css" />
		<script type="text/javascript"
			src="<%=path%>/extjs/adapter/ext/ext-base.js"></script>
		<script type="text/javascript" src="<%=path%>/extjs/ext-all.js"></script>
	<script type="text/javascript"	src="<%=path%>/menu/xtsz/template_setting.js"></script>

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	</head>
	<body>
		<div id="west-div"
			style="width: 280; height: 400px; border: 1px solid #c3daf9;"></div>
		<div id="center-div"></div>
	</body>
	<script type="text/javascript">
	
	Ext.BLANK_IMAGE_URL = "<%=path%>/extjs/resources/images/default/s.gif";
	
	Ext.onReady(function() {
		
		Ext.QuickTips.init();
		var srcUrl = "";
		var p_fbh = "";
		
		// shorthand
		var Tree_op = Ext.tree;
		var loader_op = new Tree_op.TreeLoader({
			dataUrl : 'reportInfo!findReportChartTree.do'
		});
		loader_op.on("beforeload", function(treeLoader, node) {
			loader_op.baseParams.fflag = "3";//图表分析类型树
			//loader.baseParams.fcode  = node.attributes.fcode;
		}, this);

		loader_op.processResponse = function(response, node, callback) {
			var json1 = response.responseText;
			try {
				var json = eval("(" + json1 + ")");
				node.beginUpdate();
				//从json中取得json数组
				var o = json["key"];
				for ( var i = 0, len = o.length; i < len; i++) {
					var n = this.createNode(o[i]);
					if (n) {
						node.appendChild(n);
					}
				}
				node.endUpdate();
				if (typeof callback == "function") {
					callback(this, node);
				}
			} catch (e) {
				this.handleFailure(response);
			}
		};

		var tree_op = new Tree_op.TreePanel({
			region : 'center',
			id : 'west-panel',
			el : 'west-div',
			width : 260,
			//	title : '所属区县',
			useArrows : true,
			autoScroll : true,
			animate : true,
			enableDD : true,
			containerScroll : true,
			rootVisible : false, //树根不可见 
			loader : loader_op
		});

		//单击事件
		tree_op.on('click', function(node) {
			Ext.get("fbh_id").dom.value = node.id;
			Ext.get("fname_id").dom.value = node.text;
			Ext.get("ftype_id").dom.value = node.attributes.ftype;
			if (node.isLeaf()) { //是报表
				srcUrl = "../../mould_setting/" + node.id + ".jsp?fbh='"+node.id+"'";
				
				document.getElementById("ifr_template").src = srcUrl;
				//document.getElementById("ifr_template").location.reload();
			}
		}, tree_op);

		
		// set the root node
		var root_op = new Tree_op.AsyncTreeNode({
			text : '所有报表',
			draggable : false,
			id : '0',
			fbh : '-1',
			ftype : '1'
		});
		tree_op.setRootNode(root_op);

		/**********************************   以下是报表操作方法   **************************************************************/
		var btn_add_table = new Ext.Button({
			text : '新增',
			iconCls : 'sy-add',
			handler : function() {
				var fbhStr = Ext.get("fbh_id").dom.value;
				var fnameStr = Ext.get("fname_id").dom.value;
				var ftypeStr = Ext.get("ftype_id").dom.value;
				if (ftypeStr == '1') {
					top.Ext.MessageBox.alert('提示', '不能针对报表进行新增操作！');
				} else {
					if (fbhStr) {
						add_column_fun(fbhStr, fnameStr, tree_op); //引自setting.js
					} else {
						top.Ext.MessageBox.alert('提示', '请选择下面节点再进行新增操作！');
					}
				}
			}
		});

		var btn_delete_table = new Ext.Button({
			text : '删除',
			iconCls : 'sy-delete',
			handler : function() {
				var fbhStr = Ext.get("fbh_id").dom.value;
				var ftypeStr = Ext.get("ftype_id").dom.value;
				if (ftypeStr == '1') {
					top.Ext.Msg.confirm('确认删除', '您确定删除所选报表吗,删除后将无法恢复？', function(btn) {
						if (btn == 'yes') {
							Ext.Ajax.request({
								url : 'reportInfo!deleteReportInfo.do',
								params : {
									"fbh" : fbhStr,
									"ftype" : "1"
								},
								success : function() {
									tree_op.root.reload();
									top.Ext.Msg.alert('', '删除报表成功！');
								},
								failure : function() {
									Ext.Msg.show({
										title : '错误提示',
										msg : '删除报表失败！',
										buttons : Ext.Msg.OK,
										icon : Ext.Msg.ERROR
									});
								}
							});
						}
					});
				} else {
					top.Ext.Msg.confirm('确认删除', '删除报表类别会导致该类别下面所有报表不可用，确定要删除吗？', function(btn) {
						if (btn == 'yes') {
							Ext.Ajax.request({
								url : 'reportInfo!deleteReportInfo.do',
								params : {
									"fbh" : fbhStr,
									"ftype" : "2"
								},
								success : function() {
									tree_op.root.reload();
									top.Ext.Msg.alert('', '删除报表类别成功！');
								},
								failure : function() {
									top.Ext.Msg.alert('', '删除报表类别失败！');
								}
							});
						}
					});
				}
			}
		});
		
		var btn_update_template = new Ext.Button({
			text : '更新模板',
			iconCls : 'sy-modify',
			handler : function() {
				var fbhStr = Ext.get("fbh_id").dom.value;
				var fnameStr = Ext.get("fname_id").dom.value;
				var ftypeStr = Ext.get("ftype_id").dom.value;
				
				if (ftypeStr == '1') {
					select_template_fun(fbhStr, fnameStr, tree_op); //引自setting.js
				} else {
					top.Ext.MessageBox.alert('提示', '只能针对栏目节点进行操作！');
				}
			}
		});
		
		var btn_set_template = new Ext.Button({
			text : '设置模板',
			iconCls : 'sy-modify',
			handler : function() {
				var fbhStr = Ext.get("fbh_id").dom.value;
				var fnameStr = Ext.get("fname_id").dom.value;
				var ftypeStr = Ext.get("ftype_id").dom.value;
				
				if (ftypeStr == '1') {
					mould_set_fun(fbhStr); //引自setting.js
				} else {
					top.Ext.MessageBox.alert('提示', '只能针对栏目节点进行操作！');
				}
			}
		});
		
		
		var tree_nav = new Ext.Panel({
			title : '栏目',
			region : 'west',
			split : true,
			layoutConfig:{
	            animate:true
	        },
			width : 290,
			layout : 'fit',
			autoScroll : true,
			collapsible : true,
			tbar : [ btn_add_table, '-',
					btn_delete_table, {
						xtype : 'hidden',
						id : 'fbh_id',
						name : 'fbh'
					}, {
						xtype : 'hidden',
						id : 'fname_id',
						name : 'fname'
					}, {
						xtype : 'hidden',
						id : 'ftype_id',
						name : 'ftype'
					} ],
			items : [ tree_op ]
		});
		
	    var panel = new Ext.Panel({
	    	region: "center",
			border : true,
			layout : "fit",
			title : '模板设置',
			margins:'0 5 0 0',
			tbar : [ btn_update_template, '-', btn_set_template],
			items :[{html : '<html><head></head><body><iframe name="ifr_template" id="ifr_template" scrolling="auto" frameborder="0" width="100%" height="100%" '
				+ ' src="' + srcUrl + '"></iframe></body></html>'}]
		});
	    
				
				///////////////////////////////////  列表结束  ///////////////////////////////////////////////////////
				var viewport = new Ext.Viewport({
					layout : 'border',
					items    : [tree_nav, panel ]
				});
			});
</script>


</html>